package com.lxz.jucdemo.list;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author: 刘新智
 * @Date: 2025/10/25 16:07
 * @Description: bu'wna
 * @Version: v1.0
 */
public class UnSafeListTest {
    public static void main(String[] args) {
         List<String> list1 = new Vector<>();//Vector线程安全
        List<String> list2 = Collections.synchronizedList(new ArrayList<>());//将ArrayList变为线程安全
        List<String> list3 = new CopyOnWriteArrayList<>(); // 写时复制(读写分离)比加锁更快，内部使用的是lock锁
        for (int i = 0; i < 100; i++) {
            new Thread(()->{
                list3.add(UUID.randomUUID().toString().substring(0,5));
                System.out.println(list3);
            },String.valueOf(i)).start();
        }
    }
}
